Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize internlm xcomposer2 performance #11550

Merged

Conversation

MeouSker77
Copy link
Contributor

@MeouSker77 MeouSker77 commented Jul 10, 2024

Description

optimize internlm xcomposer2 performance

1. Why the change?

2. User API changes

use following code to load model to get best performance (sym_int8 for better accuracy, sym_int4 for better speed)

from ipex_llm.transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(model_path, trust_remote_code=True,
                                             load_in_low_bit="sym_int8", modules_to_not_convert=["vit"])
model = model.half()
model = model.eval()

a complete example

import time
import torch

from ipex_llm.transformers import AutoModelForCausalLM
from transformers import AutoTokenizer

ckpt_path = "internlm-xcomposer2-vl-7b"
tokenizer = AutoTokenizer.from_pretrained(ckpt_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(ckpt_path, trust_remote_code=True,
                                             load_in_low_bit="sym_int8", modules_to_not_convert=["vit"])
model = model.half()
model = model.eval()

print(model)

query = '<ImageHere>Please describe this image in detail.'
image = 'image1.webp'

model = model.to('xpu')

with torch.inference_mode():
    for i in range(3):
        st = time.time()
        response, _ = model.chat(tokenizer, query=query, image=image, history=[], do_sample=False, max_new_tokens=1)
        et = time.time()
        print(response)
        print(et - st)

3. Summary of the change

4. How to test?

  • N/A
  • Unit test: Please manually trigger the PR Validation here by inputting the PR number (e.g., 1234). And paste your action link here once it has been successfully finished.
  • Application test
  • Document test
  • ...

@MeouSker77
Copy link
Contributor Author

@MeouSker77 MeouSker77 requested a review from rnwang04 July 10, 2024 07:27
@MeouSker77 MeouSker77 merged commit 82f9514 into intel-analytics:main Jul 10, 2024
1 check passed
@MeouSker77 MeouSker77 deleted the optimize-internlm-xcompossor branch July 10, 2024 07:57
RyuKosei pushed a commit to RyuKosei/ipex-llm that referenced this pull request Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants